using System;
using System.Text;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using LeadTracker.Models;

namespace LeadTracker.Models.MSTest
{
	
	public partial class EditorCollectionTests
	{


        

		[TestMethod]
        public void EditorCollectionTests_ListT_EditorModel_AddClear_Memory ()
		{
			IList<LeadTracker.Models.EditorModel> objectUnderTest = CreateObject();

			if (objectUnderTest.IsReadOnly)
                return;

            LeadTracker.Models.EditorModel newItem;

            try
            {
                newItem = new LeadTracker.Models.EditorModel();
                objectUnderTest.Add(newItem);
            }
            catch (ArgumentException)
            {
                //OK
                return;
            }            

        	var wr = new WeakReference(newItem);

			//release strong references
			objectUnderTest.Clear();
            newItem = null;
			
            GC.Collect();
			GC.WaitForPendingFinalizers();
			GC.Collect();

			//verify the object was collected
			Assert.IsFalse(wr.IsAlive);

		}


        [TestMethod]
        public void EditorCollectionTests_ListT_EditorModel_AddRemove_Memory ()
		{
			IList<LeadTracker.Models.EditorModel> objectUnderTest = CreateObject();

			if (objectUnderTest.IsReadOnly)
                return;

            var oldCount = objectUnderTest.Count;
            
            LeadTracker.Models.EditorModel newItem;

            try
            {
                newItem = new LeadTracker.Models.EditorModel();
                objectUnderTest.Add(newItem);
            }
            catch (ArgumentException)
            {
                //OK
                return;
            }            

        	var wr = new WeakReference(newItem);

			//release strong references
			objectUnderTest.Remove(newItem);
            newItem = null;
			
            GC.Collect();
			GC.WaitForPendingFinalizers();
			GC.Collect();

			//verify the object was collected
			Assert.IsFalse(wr.IsAlive);		
        }

        [TestMethod]
        public void EditorCollectionTests_ListT_EditorModel_AddRemoveAt_Memory ()
		{
			IList<LeadTracker.Models.EditorModel> objectUnderTest = CreateObject();

			if (objectUnderTest.IsReadOnly)
                return;

            var oldCount = objectUnderTest.Count;
            LeadTracker.Models.EditorModel newItem;

            try
            {
                newItem = new LeadTracker.Models.EditorModel();
                objectUnderTest.Add(newItem);
            }
            catch (ArgumentException)
            {
                //OK
                return;
            }            

        	var wr = new WeakReference(newItem);

			//release strong references
            var newIndex = objectUnderTest.IndexOf(newItem);
            objectUnderTest.RemoveAt(newIndex);
            newItem = null;
			
            GC.Collect();
			GC.WaitForPendingFinalizers();
			GC.Collect();

			//verify the object was collected
			Assert.IsFalse(wr.IsAlive);		
		}


        
	}
}

